package com.csit.action;

import java.io.File;
import java.io.UnsupportedEncodingException;

import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.ParentPackage;

import com.csit.util.FileUtil;
import com.csit.util.ListAndJsonUtil;

/**
 * @author longweier
 * @Description: 一些共用的方法，比如文件下载什么的
 * @Copyright: 福州骏华信息有限公司 (c)2012
 * @Created Date : 2012-8-7
 * @vesion 1.0
 */
@ParentPackage("basePackage")
public class CommonAction extends BaseAction {

	private static final long serialVersionUID = 2539768033439067529L;

	private static Logger logger = Logger.getLogger(CommonAction.class);

	private String fileName;

	/**
	 * @param
	 * @return
	 * @throws Exception
	 * @Description: 下载模板文件
	 * @Create: 2012-8-7 上午09:22:33
	 * @author longweier
	 * @update logs
	 */
	public void downloadTemplate() {
		String root = getRequest().getSession().getServletContext().getRealPath("/template");
		String path = root + File.separator + fileName;
		File file = new File(path);
		try {
			String extention = FilenameUtils.getExtension(fileName);
			FileUtil.downloadFile(getResponse(), file, "模板文件." + extention);
		} catch (UnsupportedEncodingException e) {
			logger.error("下载文件失败", e);
			e.printStackTrace();
		}
	}

	public void getRightTree() {
		try {
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void getSessionValue(){
		String sessionName = getParameter("sessionName");
		String value = (String) getSession(sessionName);
		ajaxText(value);
	}
	
	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	public void clearDataGrid(){
		ajaxJson(ListAndJsonUtil.EMPTYJSON);
	}
}
